package com.centling.smartSealForPhone.fragment

import android.content.Intent
import android.view.View
import com.centling.smartSealForPhone.R
import com.centling.smartSealForPhone.activity.BossModeActivity
import com.centling.smartSealForPhone.activity.DeviceInfoActivity
import com.centling.smartSealForPhone.activity.SealChangeActivity
import com.centling.smartSealForPhone.constants.GlobalData
import com.centling.smartSealForPhone.constants.SPConstants
import com.centling.smartSealForPhone.constants.UserType
import com.centling.smartSealForPhone.utils.GlideApp
import com.centling.smartSealForPhone.utils.SPUtil
import com.centling.smartSealForPhone.utils.ShowToast
import kotlinx.android.synthetic.main.fragment_device_manage.*

class DeviceManageFragment : TitleBarFragment(), View.OnClickListener {
    private var userType: String? = null

    override fun setLayoutResource(): Int {
        return R.layout.fragment_device_manage
    }

    override fun findViewInThisFunction(rootView: View) {
        setTitleBarText("设备管理")
        setTitleBarVisibility(View.GONE)
        userType = SPUtil.getString(SPConstants.USER_TYPE)
        initView()
    }

    private fun initView() {
        GlideApp.with(mContext).load(GlobalData.appImageEquip).placeholder(R.drawable.iv_seal_banner).into(iv_device_banner);
        ll_change_seal.setOnClickListener(this)
        ll_device_info.setOnClickListener(this)
        ll_boss_mode.setOnClickListener(this)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.ll_change_seal -> {
                if (userType == UserType.EQUIP_ADMIN) {
                    if (GlobalData.isInFixMode) {
                        ShowToast.shortTime("设备当前处于维修模式")
                    } else {
                        startActivity(Intent(activity, SealChangeActivity::class.java))
                    }
                } else {
                    ShowToast.shortTime("您没有换章的权限！")
                }
            }
            R.id.ll_device_info -> {
                startActivity(Intent(mContext, DeviceInfoActivity::class.java))
            }
            R.id.ll_boss_mode -> {
                if (GlobalData.isInFixMode) {
                    ShowToast.shortTime("设备当前处于维修模式")
                } else {
                    startActivity(Intent(activity, BossModeActivity::class.java))
                }
            }
        }
    }
}
